
public class Square implements Comparable<Square> {
	private PlayingField pf;
	private Board board;
	private Piece occ;
	private int level;
	private int col;
	private int row;
	
	public static final int NORTH = 0;
	public static final int NORTHEAST = 45;
	public static final int EAST = 90;
	public static final int SOUTHEAST = 135;
	public static final int SOUTH = 180;
	public static final int SOUTHWEST = 225;
	public static final int WEST = 270;
	public static final int NORTHWEST = 315;
	public static final int UP = 1;
	public static final int DOWN = -1;
	
	public Square(int l, int c, int r) {
		level = l;
		col = c;
		row = r;
	}
	
	public Piece getPiece() {
		return occ;
	}
	
	public void setPiece(Piece add) {
		occ = add;
	}
	
	public boolean addPiece(Piece add){
		if (occ == null) {
			occ = add;
		}
		add.setPF(this.pf);
		add.setBoard(this.board);
		add.setSquare(this);
		return occ.equals(add);
	}
	
	public void removePiece() {
		occ = null;
	}
	
	public PlayingField getPF() {
		return pf;
	}
	
	public void setPF(PlayingField pf) {
		this.pf = pf;
	}
	
	public Board getBoard() {
		return board;
	}
	
	public void setBoard(Board b) {
		board = b;
	}
	
	public int getLevel() {
		return level;
	}
	
	public int getCol() {
		return col;
	}
	
	public int getRow() {
		return row;
	}
	
	/* assuming a real direction is input*/
	public Square getFarSquare(int dir, int away) {
		int db = 0;
		int dc = 0;
		int dr = 0;
		if(dir == NORTH) {
			dr = -away;
		} else if(dir == NORTHEAST) {
			dc = away;
			dr = -away;
		} else if(dir == EAST) {
			dc = away;
		} else if(dir == SOUTHEAST) {
			dc = away;
			dr = away;
		} else if(dir == SOUTH) {
			dr = away;
		} else if(dir == SOUTHWEST) {
			dc = -away;
			dr = away;
		} else if(dir == WEST) {
			dc = -away;
		} else if(dir == NORTHWEST) {
			dc = -away;
			dr = -away;
		} else if(dir == UP || dir == DOWN) {
			db = dir * away;
		}
		return board.getPF().getSquare(level + db, col + dc, row + dr);
	}
	
	public boolean isOccupied() {
		return occ != null;
	}
	
	public boolean isValid() {
		return row >= 0 && col >= 0 && row <= 8 && col <= 12;
	}
	
	public boolean equals(Square other) {
		return row == other.row && col == other.col;
	}
	
	public int compareTo(Square other){
		if (row - other.row > 0) {
			return 1;
		} else if (row - other.row < 0) {
			return -1;
		} else {
			return col - other.col;
		}
	}
	
	public String toString() {
		return "(" + level + "," + col + "," + row + ", " + occ + ")";
	}
}
